/**
 * Copyright (C), 2015-2020, XXX有限公司
 * FileName: TripPlanDesPop
 * Author: Clark
 * Date: 2020/10/8 19:40
 * Description:
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
package sz.szsmk.citizencard.ui.popwindow;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


import java.util.ArrayList;
import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.bean.response.PoiBean;
import sz.szsmk.citizencard.ui.adapter.CalenderForPopWindowAdapter;
import sz.szsmk.citizencard.ui.adapter.PoiListAdapter;

/**
 * @ClassName: TripPlanDesPop
 * @Description:
 * @Author: Clark
 * @Date: 2020/10/8 19:40
 */
class TripPlanDesPop extends PopupWindow {

    View mPopView;

    RecyclerView recycle_list;
    private TripPlanDesPop.OnItemClickListener mListener;
    private Context context;

    public TripPlanDesPop(final Context context) {
        super(context);
        this.context = context;
        initView(context);
        setPopupWindow();
    }

    private void initView(Context context) {
        LayoutInflater inflater = LayoutInflater.from(context);
        mPopView = inflater.inflate(R.layout.pop_tripplan_des, null);
        recycle_list  = mPopView.findViewById(R.id.trip_pop_des_list);

        PoiListAdapter poiListAdapter=new PoiListAdapter(context);



        recycle_list.setLayoutManager(new LinearLayoutManager(context));

        recycle_list.addItemDecoration(new DividerItemDecoration(context,DividerItemDecoration.VERTICAL));
        recycle_list.setAdapter(poiListAdapter);


        List<PoiBean> list=new ArrayList<>();
       poiListAdapter.setViewData(list);

    }

    private void setPopupWindow() {
        this.setContentView(mPopView);// 设置View
//        this.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);// 设置弹出窗口的宽

        this.setHeight(LinearLayout.LayoutParams.MATCH_PARENT);// 设置弹出窗口的高

        this.setFocusable(true);// 设置弹出窗口可
        this.setAnimationStyle(R.style.mypopwindow_anim_style);// 设置动画
        this.setBackgroundDrawable(new ColorDrawable(0x00000000));// 设置背景透明
        mPopView.setOnTouchListener(new View.OnTouchListener() {// 如果触摸位置在窗口外面则销毁

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
    }

    /**
     * 显示popupWindow
     *
     * @param parent
     */
    public void showPopupWindow(View parent) {
        if (!this.isShowing()) {
            // 以下拉方式显示popupwindow
            this.showAsDropDown(parent, -15, 10);
        } else {
            this.dismiss();
        }
    }

    /**
     * 定义一个接口，公布出去 在Activity中操作按钮的单击事件
     */
    public interface OnItemClickListener {
        void setOnItemClick(String data);
    }

    public void setOnItemClickListener(TripPlanDesPop.OnItemClickListener listener) {
        this.mListener = listener;
    }
}